package com.usian.day02.order.controller;

import com.usian.common.utils.AliyunOSSClientUtil;
import com.usian.common.vo.ResultResopnse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author baimugudu
 * @email 2415621370@qq.com
 * @date 2023/8/4 9:09
 */
@RestController
@RequestMapping("file")
@Slf4j
public class FileController {

    @RequestMapping
    public ResultResopnse uploadFile(MultipartFile file) {
        AliyunOSSClientUtil aliyunOSSClientUtil = new AliyunOSSClientUtil();
        String img2Oss = null;
        try {
            img2Oss = aliyunOSSClientUtil.uploadImg2Oss(file);
            log.info("img2Oss:{}",img2Oss);
            String imgUrl = aliyunOSSClientUtil.getImgUrl(img2Oss);
            log.info("imgUrl:{}",imgUrl);
            return ResultResopnse.success(imgUrl);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResopnse.error();
        }




    }
}
